using System.Collections.Generic;
using Belmost4PDA.Constants;
using Belmost4PDA.Fasade;

namespace Belmost4PDA.Logic
{
    public class CmdCancel:AbstractCommand
    {
        public CmdReadData cmd=null;
        public override void Execute(ref AbstractState currentState, ref AbstractControl TopControl,
                                     ref List<AbstractMapper> AllMappers)
        {
            if (currentState.AskToDo(this))
            {
                //if (currentState.IsInserting)

                    if (!((Control_Main)TopControl).EmptyGrid)
                    {
                        if (cmd == null)
                        {
                            if(((Control_Main) TopControl).GetGrid()!=null)
                            cmd = new CmdReadData(((Control_Main) TopControl).GridIDValue,
                                                  ((Control_Grid) TopControl.GetGrid()).GetIdFieldName());
                            else
                            {
                                cmd = new CmdReadData();
                            }
                        }
                   }
                   //else if (cmd == null) cmd = new CmdReadData();
                InterfaceDispatcher.SetState(new StateView());
                if (cmd != null) InterfaceDispatcher.ExecCommand(cmd);
                cmd = null;
            }
        }

        public override CommandID GetID()
        {
            return CommandID.Cancel;
        }
    }
}
